<?php


class WacFinalClothFormItemConsumeTable extends WacCommonTable
{
    
    public static function getInstance()
    {
        return Doctrine_Core::getTable('WacFinalClothFormItemConsume');
    }

    public function findOneByOrderItemAndGoods($orderItemId, $goodsId, $isArr=false)
    {
        $objQuery = $this->createQuery('t1')
                ->select('t1.*')
                ->from("WacFinalClothFormItemConsume t1")
                ->where("t1.item_id=? and t1.goods_id=?", array($orderItemId, $goodsId));

        if($isArr)
        {
            $dataResult = $objQuery->fetchOne(array(), Doctrine::HYDRATE_ARRAY);
        }
        else{
            $dataResult = $objQuery->fetchOne();
        }

        $objQuery->free();
        return $dataResult;
    }

    public function findOneByOrderAndGoods($orderId, $goodsId, $isArr=false)
    {
        $objQuery = $this->createQuery('t1')
                ->select('t1.*')
                ->from("WacFinalClothFormItemConsume t1")
                ->where("t1.final_cloth_form_id=? and t1.goods_id=?", array($orderId, $goodsId));

        if($isArr)
        {
            $dataResult = $objQuery->fetchOne(array(), Doctrine::HYDRATE_ARRAY);
        }
        else{
            $dataResult = $objQuery->fetchOne();
        }

        $objQuery->free();
        return $dataResult;
    }

    /*
     * get item corresponding consume
     */
    public function getListByItem($objItem, $page=1, $rows=1)
    {
        $condParams = array();
        $condParams['orderBy'] = "t1.id asc";
        $condParams['andWhere'][] = "t1.is_avail=1";
        $condParams['andWhere'][] = "t1.final_cloth_form_id='".$objItem->getFinalClothFormId()."'";
        $condParams['andWhere'][] = "t1.item_id='".$objItem->getId()."'";
        return $this->getCustomList($condParams, $page, $rows, false);
    }
}